/**
 * Copyright(c) 2013 Jade Techonologies Co., Ltd.
 *
 * History:
 *   13-4-14 下午11:41 Created by dwzhang
 */
package com.jade.framework.base.pattern.pipeline;

import java.util.ArrayList;
import java.util.List;

/**
 * ListValve阀门内置一组阀门，在List中的阀门将依次执行，并且不能够使用chain的操作。
 *
 * @author dwzhang
 * @version 1.0 13-4-14 下午11:41
 */
public class ListValve<Context, E extends Exception> extends Valve<Context, E>
{
    private List<Valve<Context, E>> valves = new ArrayList<Valve<Context, E>>();

    public void setValves(List<Valve<Context, E>> valves)
    {
        this.valves = valves;
    }

    public void addValve(Valve<Context, E> valve)
    {
        valves.add(valve);
    }

    @Override
    public void handle(Context context, ValveChain<Context, E> contextEValveChain)
            throws E
    {
        for (Valve<Context, E> valve : valves) {
            try {
                valve.handle(context, null);
            }
            catch (Throwable t) {
                // do nothing
            }
        }
    }
}
